package cn.wolfcode.ssm.service.impl;

import cn.wolfcode.ssm.domain.SystemDictionaryItem;
import cn.wolfcode.ssm.mapper.SystemDictionaryItemMapper;
import cn.wolfcode.ssm.qo.QueryObject;
import cn.wolfcode.ssm.service.ISystemDictionaryItemService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SystemDictionaryItemServiceImpl implements ISystemDictionaryItemService {

    @Autowired
    private SystemDictionaryItemMapper systemDictionaryItemMapper;
    @Override
    public void delete(Long id) {
        systemDictionaryItemMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void save(SystemDictionaryItem systemDictionaryItem) {
        systemDictionaryItemMapper.insert(systemDictionaryItem);
    }

    @Override
    public SystemDictionaryItem getOne(Long id) {
        return systemDictionaryItemMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<SystemDictionaryItem> getAll() {
        return systemDictionaryItemMapper.selectAll();
    }

    @Override
    public void update(SystemDictionaryItem systemDictionaryItem) {
        systemDictionaryItemMapper.updateByPrimaryKey(systemDictionaryItem);
    }


    @Override
    public PageInfo<SystemDictionaryItem> selctForPageResult(QueryObject qo) {
        //使用分页插件,传入当前页,每页显示数量,次序按照正序排序
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize(),"sequence asc");
        List<SystemDictionaryItem> systemDictionaryItems = systemDictionaryItemMapper.selectForResult(qo);
        return new PageInfo(systemDictionaryItems);
    }

    @Override
    public int getMaxSequence(Long parentId) {
        return systemDictionaryItemMapper.getMaxSequence(parentId);
    }

    @Override
    public List<SystemDictionaryItem> selectByParentsn(String sn) {
        return systemDictionaryItemMapper.selectByParentsn(sn);
    }
}
